package com.example.demo.util;

/**
 * 将字符串转换成16进制 高位在前
 *
 * @author yudidi
 */
public class StringReverseUtils {
    public static String enUnicode(String content) {//将汉字转换为16进制数
        String enUnicode = null;
        for (int i = 0; i < content.length(); i++) {
            if (i == 0) {
                enUnicode = getHexString(Integer.toHexString(content.charAt(i)).toUpperCase());
                StringBuilder b = new StringBuilder(enUnicode);
                b.reverse();
                enUnicode = b.toString();

            } else {
                String enUnicode2 = getHexString(Integer.toHexString(content.charAt(i)).toUpperCase());
                StringBuilder b = new StringBuilder(enUnicode2);
                b.reverse();
                enUnicode2 = b.toString();
                enUnicode = enUnicode + enUnicode2;
            }
        }
        return enUnicode;
    }

    private static String getHexString(String hexString) {
        String hexStr = "";
        for (int i = hexString.length(); i < 2; i++) {
            if (i == hexString.length())
                hexStr = "0";
            else
                hexStr = hexStr + "0";
        }
        return hexStr + hexString;
    }


}
